import methodMixin from './methodMixin.js'

export default {
    mixins: [methodMixin],
    // 分享
    onShareAppMessage(res) {
        let shareData = {
            title: '我发现了一个超好用的视频帮卖小程序！快来一起玩转私域流量！',
            imageUrl: `https://image.qqpyyds.com/mpAppImg/bgImg/homePageShare_img.png?t=${Date.parse(new Date())}`,
            path: '/pages/index/index'
        }
        if (res.from === 'button') {
            switch (res.target.id) {
                case 'publishId':
                    shareData = this.publishIdShare()
                    break
                case 'sharewx':
                    shareData = this.sharewxShare(shareData)
                    break
                case 'nviteEarn':
                    shareData.title = this.inviteOthersShareData.title
                    shareData.imageUrl = this.inviteOthersShareData.imageUrl
                    shareData.path = this.inviteOthersShareData.path
                    break
                case 'shareFriends':
                    const {title, url, shopWindowId} = this.shareObject
                    shareData.title = title
                    shareData.imageUrl = url
                    shareData.path = `pagesB/goods/goodsDetails?shopWindowId=${shopWindowId}&shareType=true&idCode=${this.$store.state.userInfo.idCode}`
                    break
            }
        }
        // 分享参数打印
        console.log(JSON.parse(JSON.stringify({
            title: shareData.title,
            imageUrl: shareData.imageUrl,
            path: shareData.path,
        })), '分享参数打印')

        return shareData
    },
    // res.target.id === 'publishId'
    methods: {
        publishIdShare() {
            // 开团邀请好友
            const shareData = {
                title: this.shareObject.title,
                imageUrl: this.shareObject.url,
                path: `/pagesB/dynamic/${this.shareObject.mediaType && this.shareObject.mediaType === 1 ? 'graphicsDetail' : 'videoDetail'}?dynamicId=${this.shareObject.dynamicId}&shareType=true&type=2&idCode=${this.$store.state.userInfo.idCode}`
            }
            if (this.$store.state.userInfo.isSubscribe === 0) {
                this.attendOfficialText = '关注公众号，第一时间收到出单信息'
                this.dlAttendOfficial = true
            }
            return shareData
        },
        // res.target.id === 'sharewx'
        sharewxShare(shareData) {
            shareData.path = `/pagesB/dynamic/${this.shareObject.mediaType && this.shareObject.mediaType === 1 ? 'graphicsDetail' : 'videoDetail'}?dynamicId=${this.shareObject.dynamicId}&shareType=true&type=99&idCode=${this.$store.state.userInfo.idCode}`
            // 公用的分享
            const commonShare = this.$store.state.pageSharingData
            if (Object.prototype.hasOwnProperty.call(commonShare, 'url')) {
                if (commonShare.isShareType === 2) {
                    // 邀请帮卖
                    shareData.path = `/pagesB/dynamic/${this.shareObject.mediaType && this.shareObject.mediaType === 1 ? 'graphicsDetail' : 'videoDetail'}?dynamicId=${this.shareObject.dynamicId}&shareType=true&type=99&applyForHelp=true&idCode=${this.$store.state.userInfo.idCode}`
                    if (this.$store.state.userInfo.isSubscribe == 0) {
                        this.attendOfficialText = '关注公众号，第一时间收到帮卖申请通知'
                        this.dlAttendOfficial = true
                    }
                }
                shareData.title = commonShare.title
                shareData.imageUrl = commonShare.url
            }
            return shareData
        },
    }
}